//
//  PXGafaerProtocolViewController.m
//  Gafaer
//
//  Created by lanjue on 16/3/31.
//  Copyright © 2016年 lanjue. All rights reserved.
//

#import "PXGafaerProtocolViewController.h"

@interface PXGafaerProtocolViewController ()<UIWebViewDelegate>
@property (nonatomic ,strong)UIWebView *protocolWeb;
@end

@implementation PXGafaerProtocolViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.navigationController.navigationBarHidden = NO;
    self.automaticallyAdjustsScrollViewInsets = NO;
    //隐藏tabbar
    UIView *bgview = [self.tabBarController.view viewWithTag:55];
    bgview.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNav];
    // Do any additional setup after loading the view.
    self.view.backgroundColor                           = MainBtnUColor;
    NSURL *protocolURL                                  = [NSURL URLWithString:_webStr];
    NSURLRequest *request                               = [NSURLRequest requestWithURL:protocolURL];
    
    _protocolWeb                              = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    _protocolWeb.delegate = self;
    [_protocolWeb setScalesPageToFit:YES];
    [_protocolWeb loadRequest:request];
    [self.view addSubview:_protocolWeb];

    __weak __typeof(self) weakSelf = self;
    _protocolWeb.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf.protocolWeb loadRequest:request];
    }];
}

- (void)setNav{

    self.navigationController.navigationBar.translucent = NO;

    UIButton *leftButton                                = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame                                    = CGRectMake(0, 0, 30, 30);
        [leftButton setBackgroundImage:[UIImage imageNamed:@"dacha"] forState:UIControlStateNormal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftButton];

    [leftButton addTarget:self action:@selector(pushToSearchVC) forControlEvents:UIControlEventTouchUpInside];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [_protocolWeb.scrollView.mj_header endRefreshing];
}

- (void)pushToSearchVC{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
